<?php 
if(!isset($_SESSION)) 
{ 
session_start(); 
} 	
if(!isset($_REQUEST['page'])){
$list["em.FullName"]="ASC";
$list["em.Positionsit"]="ASC";
$list["em.Email"]="ASC";
$list["dpl.DepartmentName"]="ASC";
$list["em.Position"]="ASC";
$list["em.StartDate"]="ASC";
$str="em.FullName";
$_SESSION['sortemn']=$str;
$_SESSION['sortem']=$list;
}else{
	$str=$_SESSION['sortemn'];
	$list=$_SESSION['sortem'];
}
	$rows_per_page = 10;
	$page_start = ( $page - 1 ) * $rows_per_page; 
	$page_end = $page * $rows_per_page;
	
	unset($_SESSION['searchstring']);
	$str1=$str;	
	if($str=="em.FullName")
		$str1="SUBSTRING_INDEX(em.FullName, ' ', -1)";
	$order_by = " order by ".$str1." ".$list[$str];
	$_SESSION['searchstring'] = "";
	
	$listemployeePage = mysql_query("SELECT em.IDEmployee,em.FullName,em.Positionsit,em.Image FROM employee em left JOIN department_lang dpl
	 on em.IDDepartment = dpl.IDDepartment where em.State = 1 and em.IDRole != 1 and  dpl.LangID='".$lang."' ".$order_by);
	
	
	$listemployee = mysql_query("SELECT em.IDEmployee,em.UserName, em.FullName,em.Positionsit,em.Email,em.StartDate ,dpl.DepartmentName, em.Position ,em.Sex, em.IDDepartment,em.Phone,em.Birthday FROM employee em left JOIN department_lang dpl
	 on em.IDDepartment = dpl.IDDepartment where em.State = 1 and em.IDRole != 1 and dpl.LangID='".$lang."' ".$order_by." limit ".$page_start.",".$rows_per_page);
	$number_of_page_employees = ceil ( mysql_num_rows( $listemployeePage ) / $rows_per_page );
	$mang=array();
	while ($r=mysql_fetch_array($listemployeePage)){
		$mang[]=array($r['IDEmployee'],$r['FullName'],$r['Positionsit'],$r['Image']);
	}
	
	//search
	$listDepartments = mysql_query("select department_lang.IDDepartment,department_lang.DepartmentName,department_lang.LangID 
					from department_lang where department_lang.LangID = '".$lang."'");
	
	$listSex = mysql_query("select SexID,SexName from ac_sex_lang WHERE LangID='".$lang."'");
	
function getvitri($m,$possit){
	$kq=array();
	foreach($m as $value){
		if($value[2]==$possit){
			$kq=array($value[1],$value[3]);
		}
	}
	return $kq;
}

?>

<script type="text/javascript">
//alert(testers);

function sortem(page,str){
	var departments = $('select#searchDepartment').val();
	$.ajax({url:"ajax/sortemployee.php", data : { pages : page , strs : str }, success:function(result){
		$("table#lstems tr").remove();
		$("table#lstems tbody").append(result);
	}});
}


function paging(page,str){
	//alert(page+"-"+str);
	$.ajax({url:"ajax/ajaxpagingemployee.php", data : { pages : page , strs : str}, success:function(result){
		$("table#lstems tr").remove();
		$("table#lstems tbody").append(result);
	}});
}
function searchChangeDepartment(){	
	var departments = $('select#searchDepartment').val();
	$.ajax({url:"ajax/ajaxsearchauto.php", data : { department : departments }, success:function(result){
		$("table#lstems tr").remove();
		$("table#lstems tbody").append(result);
	}});
}



</script>

<div id="contains" style="background-color: #edf4f7;">

	<div class="title"></div>
	<div class="main_content"  style="min-height: 895px">  
            <div style="width: 100%; margin-top:5px">
				<table cellpadding="5" cellspacing="5" style="width: 100%">
	               
	               
	                <tr>
		                <td class="rf-dt-ftr-c" style="text-align: left;">
		                	<select onchange="searchChangeDepartment()" class="com_tit" id="searchDepartment">
		                		<option value="0"><?=$l_all?></option>
		                		<?php while ($rows = mysql_fetch_array($listDepartments)){?>
		                			<option value="<?=$rows[IDDepartment]?>"><?=$rows[DepartmentName]?></option>
		                		<?php }?>
		                	</select>
		                </td>
	                </tr>
	             </table>
			</div>
            <div id="listEmps" style="min-height: 430px;">
            	<table cellpadding="5" cellspacing="0" class="rf_dt" id="lstems">
	                <tr  class="table_new">
	                	<td width="3%"><?=$l_no?></td>
		                <td width="15%"><a href="#" onclick="sortem(1,'em.Fullname')"><?=$l_fullname?></a></td>
		                <td width="8%"><a href="#" onclick="sortem(1,'dpl.DepartmentName')"><?=$l_department?></a></td>
		                <td width="8%"><a href="#" onclick="sortem(1,'em.Positionsit')"><?=$l_position?></a></td>
		                <td width="20%"><a href="#" onclick="sortem(1,'em.Email')"><?=$l_email?></a></td>
		                <td width="8%"><a href="#" onclick="sortem(1,'em.Phone')"><?=$l_phone?></a></td>
		                <td width="8%"><a href="#" onclick="sortem(1,'em.Birthday')"><?=$l_birthday?></a></td>
		                <td width="8%"><a href="#" onclick="sortem(1,'em.StartDate')"><?=$l_start_date?></a></td>
		                
		                <td width="20%"><a href="#" onclick="sortem(1,'em.Position')"><?=$l_sitting_position?></a></td>
	                </tr>
	                 <?php 
	                 unset($_SESSION['lstemps']);
	                $temp_lstemps = array();
	                $i=0;
	                while ($row=mysql_fetch_array($listemployee)){ 
	                	array_push($temp_lstemps, array($row['IDEmployee'],$row['UserName'],$row['FullName'],$row['DepartmentName'],$row['Position'],$row['Sex'],$row['IDDepartment'],$row['StartDate']));
	                	$i++;
					?>
	                <tr>
	                	<td align="center"><?=$i?></td>
		                <td align="center" class="FullName"><?=$row['FullName']?></td>
		                <td align="center"><?=$row['DepartmentName']?></td>
		                <td align="center" class="IDEmployee"><?=$row['Position']?><input type="hidden" value="<?=$row['IDEmployee']?>"/></td>
		                <td align="center"><?=$row['Email']?></td>
		                <td align="center"><?=$row['Phone']?></td>
		                <td align="center"><?=$row['Birthday']?></td>
		                <td align="center"><?=$row['StartDate']?></td>
		                <td align="left">
		                
						<?php 
						if(isset($row['Positionsit'])){
							if($row['Positionsit']!=""){
								
								$p=explode('-', $row['Positionsit']);
								echo "Lau :".$p[0]." - Phong :".$p[1]." - Vi tri :".$p[2];
							}
								
						}
						
						?>
		                
		                </td>
	                </tr>
	                <?php }
	                $_SESSION['lstemps'] = $temp_lstemps;
	                $temp_lstemps = null;
	                ?>
	                <tr class="trfoot">
	                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="9">
	                        	<div style="text-align: center; width8000%">
	                            	<span class="rf-ds">
															
															<?php if ( $number_of_page_employees > 1 ) 
															{ 
																if ($page==1)
																	$p=2;
																else if ($page==$number_of_page_employees)
																	$p=$number_of_page_employees-1;
																else $p=$page;
																if($page!=1){?>
																	<a onclick="paging(1,'<?=$str?>')" ><span class='button_next'><?php echo "<<<";?></span> </a>
																	<a onclick="paging(<?=($page-1)?>,'<?=$str?>')" ><span class='button_next'><?php echo "<<";?></span> </a>
																<?php  }
																else{
																	echo "<span class='button_next'><<<</span>"; 
																	echo "<span class='button_next'><<</span>";
																}
																for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																		if ($i<=$number_of_page_employees && $i>0)
																		
																			if ($i==$page){
																				echo "<span class='button_next' style='color: #000'><i>".$i."</i></span>"; 
																			}else{
																			?>
																				<a onclick="paging(<?=$i?>,'<?=$str?>')" ><span class="button_next">
																				<?php 
																				echo $i;
																				?>
																				</span> </a>
																			<?php 
																			}
																		?>
																	
																<?php 
																		}
																	
																	if($page!=$number_of_page_employees){ ?>
																		<a onclick="paging(<?=($page+1)?>,'<?=$str?>')"><span class='button_next'><?php echo ">>";?></span> </a>
																		<a onclick="paging(<?=($number_of_page_employees)?>,'<?=$str?>')" ><span class='button_next'><?php echo ">>>";?></span> </a>
																	<?php }
																	else{
																		echo "<span class='button_next'>>></span> ";
																		echo "<span class='button_next'>>>></span> ";
																	}
																}
															
																
																?>
																													
														</span>
														</div>
														</td>
	                    </tr> 
	            </table>
	    
	   
            </div>  
        
<div class="tr_title">Lau 1 -Phong 1 </div>	<br>	  
<table>
<tr>
<td style="vertical-align: bottom;"><img alt="" src="icon/logout.png" ></td>
<td>    
<table  border="1">
 
  <tr>
  	<?php $kq=getvitri($mang, "1-1-6");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "1-1-7");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "1-1-8");?>
    <td colspan="2" style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    
    <?php $kq=getvitri($mang, "1-1-10");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
  <tr>
    <?php $kq=getvitri($mang, "1-1-1");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "1-1-2");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "1-1-3");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "1-1-4");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "1-1-5");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
</table>
</td>
</tr>
</table> 
<br>
<br>
<table style="width: 100%;">
<tr>
<td style="vertical-align: top;width: 50%;">


<div class="tr_title">Lau 2 -Phong 1 </div>	<br>
<table>
<tr>
<td style="vertical-align: top;"><img alt="" src="icon/logout.png"></td>
<td>    
<table  border="1">
 
  <tr>
  	<?php $kq=getvitri($mang, "2-1-1");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "2-1-2");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
	<td colspan="2"></td>
	
  </tr>
  <tr>
    <td colspan="2"></td>
    <?php $kq=getvitri($mang, "2-1-5");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "2-1-6");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
  <tr>
    <td colspan="2"></td>
    <?php $kq=getvitri($mang, "2-1-7");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "2-1-8");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
   <tr>
   	<?php $kq=getvitri($mang, "2-1-3");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "2-1-4");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
   
    <td colspan="2"></td>
  </tr>
</table>
</td>
</tr>
</table> 
</td>
<td style="vertical-align: top;width: 50%;">

<div class="tr_title">Lau 2 -Phong 2 </div>	<br>
<table>
<tr>
<td style="vertical-align: bottom;"><img alt="" src="icon/logout.png" ></td>
<td>    
<table  border="1">
 
  <tr>
  	<?php $kq=getvitri($mang, "2-2-4");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "2-2-3");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
  <tr>
  	<?php $kq=getvitri($mang, "2-2-1");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "2-2-2");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
</table>
</td>
</tr>
</table> 
</td>
</tr>
</table>
<br><br>


<table style="width: 100%;">
<tr>
<td style="vertical-align: top;width: 50%;">


<div class="tr_title">Lau 3 -Phong 1 </div>	<br>
<table>
<tr>
<td style="vertical-align: top;"><img alt="" src="icon/logout.png"></td>
<td>    
<table  border="1">
 
  <tr>
  	<?php $kq=getvitri($mang, "3-1-1");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "3-1-2");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
	<td colspan="2"></td>
	
  </tr>
  <tr>
    <td colspan="2"></td>
    <?php $kq=getvitri($mang, "3-1-5");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "3-1-6");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
  <tr>
    <td colspan="2"></td>
    <?php $kq=getvitri($mang, "3-1-7");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "3-1-8");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
   <tr>
   	<?php $kq=getvitri($mang, "3-1-3");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "3-1-4");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
   
    <td colspan="2"></td>
  </tr>
</table>
</td>
</tr>
</table> 
</td>
<td style="vertical-align: top;width: 50%;">

<div class="tr_title">Lau 3 -Phong 2 </div>	<br>
<table>
<tr>
<td style="vertical-align: bottom;"><img alt="" src="icon/logout.png" ></td>
<td>    
<table  border="1">
 
  <tr>
  	<?php $kq=getvitri($mang, "3-2-4");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "3-2-3");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
  <tr>
  	<?php $kq=getvitri($mang, "3-2-1");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "3-2-2");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
</table>
</td>
</tr>
</table> 
</td>
</tr>
</table>
<br><br>

<table style="width: 100%;">
<tr>
<td style="vertical-align: top;width: 50%;">


<div class="tr_title">Lau 4 -Phong 1 </div>	<br>
<table>
<tr>
<td style="vertical-align: top;"><img alt="" src="icon/logout.png"></td>
<td>    
<table  border="1">
 
  <tr>
  	<?php $kq=getvitri($mang, "4-1-1");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "4-1-2");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
	<td colspan="2"></td>
	
  </tr>
  <tr>
    <td colspan="2"></td>
    <?php $kq=getvitri($mang, "4-1-5");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "4-1-6");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
  <tr>
    <td colspan="2"></td>
    <?php $kq=getvitri($mang, "4-1-7");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "4-1-8");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
  </tr>
   <tr>
   	<?php $kq=getvitri($mang, "4-1-3");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
    <?php $kq=getvitri($mang, "4-1-4");?>
    <td style="text-align:center;vertical-align: middle;width: 80px;height: 80px;"><img src="<?=$kq[1]?>" style="width: 70px;height: 80px"><br><?=$kq[0]?></td>
   
    <td colspan="2"></td>
  </tr>
</table>
</td>
</tr>
</table> 
</td>
<td style="vertical-align: top;width: 50%;">



</td>
</tr>
</table>
<br><br>
			
</div>	
	
	
</div>

